package com.poisonh.unifiedauth.adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.poisonh.unifiedauth.R;
import com.poisonh.unifiedauth.model.VerRecordModel;

import net.karthikraj.shapesimage.ShapesImage;

import java.util.ArrayList;
import java.util.List;


/**
 * 验证记录数据适配器
 * Created by PoisonH on 2016/7/21.
 */

public class RvVerRecordAdapter extends RecyclerView.Adapter<RvVerRecordAdapter.MyViewHolder>
{
    private Context mContext;
    private List<VerRecordModel> mVerRecordLists;

    public RvVerRecordAdapter(Context context)
    {
        this.mContext = context.getApplicationContext();
        mVerRecordLists = new ArrayList<>();
    }

    @Override
    public int getItemCount()
    {
        return mVerRecordLists.size();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.layout_verrecord_item, parent, false));
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position)
    {
        holder.mTvTime.setText(mVerRecordLists.get(position).gettime());
        holder.mTvName.setText(mVerRecordLists.get(position).getname());
//        Glide.with(mContext).load(ConstantUitls.REQUEDT_IMG_URL + mVerRecordLists.get(position).getHEADURL()).into(holder.mIvHead);
        Glide.with(mContext).load(R.mipmap.pakistan_gun).into(holder.mIvHead);
    }

    protected class MyViewHolder extends RecyclerView.ViewHolder
    {
        private TextView mTvName;
        private TextView mTvTime;
        private ShapesImage mIvHead;

        protected MyViewHolder(View view)
        {
            super(view);
            mTvName = (TextView) view.findViewById(R.id.tv_name);
            mTvTime = (TextView) view.findViewById(R.id.tv_time);
            mIvHead = (ShapesImage) view.findViewById(R.id.iv_head);
        }
    }

    public void notif(List<VerRecordModel> list)
    {
        this.mVerRecordLists.addAll(mVerRecordLists.size(), list);
        this.notifyDataSetChanged();
    }

    public void update(List<VerRecordModel> list)
    {
        if (mVerRecordLists.size() > 0)
        {
            mVerRecordLists.clear();
        }
        this.mVerRecordLists.addAll(list);
        this.notifyDataSetChanged();
    }


}
